<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        padding: 0;
        margin: 0;
      }
      html,
      body {
        width: 100vw;
        height: 100vh;
      }
      .container {
        width: 100%;
        height: 100%;
        background-color: red;
        background: url('./bg.png') no-repeat center center / cover;
      }
      .box {
        position: fixed;
        width: 1920px;
        height: 1080px;
        background-color: skyblue;
        overflow: hidden;
        transform-origin: left top;
        left: 50%;
        top: 50%;
      }
      .box1 {
        width: 200px;
        height: 200px;
        background-color: firebrick;
        margin-left: 50px;
        margin-top: 50px;
      }
      .box2 {
        width: 200px;
        height: 200px;
        background-color: darkcyan;
        margin-left: 50px;
        margin-top: 50px;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="box">
        <div class="box1">盒子1</div>
        <div class="box2">盒子2</div>
      </div>
      <script>
        // 计算缩放的比例
        const getScale = (w = 1920, h = 1080) => {
          const ww = window.innerWidth / w
          const wh = window.innerHeight / h
          return ww < wh ? ww : wh
        }
        // 控制屏幕的缩放和放大
        const box = document.querySelector('.box')

        window.onresize = () =>{
            box.style.transform = `scale(${getScale()}) translate(-50%,-50%)`
        }
      </script>
    </div>
  </body>
</html>
